<template>
  <t-form ref="form"   class="step-form table-form"
          style="height:100%;overflow-y: auto"
          labelWidth="180px">
    <t-row>
      <t-col :span="2" class="title">科技示范工程名称</t-col>
      <t-col :span="10">{{ implementPlanData.projectName }}</t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title">负责人</t-col>
      <t-col :span="10">{{ projectData.projectLeader.name }}</t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title">第一承担单位</t-col>
      <t-col :span="10">{{ projectData.declareDeptName }}</t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title">合作单位</t-col>
      <t-col :span="10">{{ companyList.join(',') }}</t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title">实施起止年月</t-col>
      <t-col :span="10">{{ implementPlanData.startDate.substring(0, 4) }} 年 {{ implementPlanData.startDate.substring(5, 7) }} 月 至
        {{ implementPlanData.endDate.substring(0, 4) }} 年 {{ implementPlanData.endDate.substring(5, 7) }} 月
      </t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title"><span class="require">*</span>申请验收时间</t-col>
      <t-col :span="4">
        <t-form-item name="acceptanceDate">
          {{parseTime(formData.acceptanceDate,'{y}-{m}-{d}') }}
        </t-form-item>
      </t-col>
      <t-col :span="6" style="display: flex;flex-direction: column;border: 0;padding: 0px !important">
        <t-row style="width: 100%;">
          <t-col :span="2" class="title"><span class="require">*</span>联系人</t-col>
          <t-col :span="10">
            <t-form-item name="linker">
              {{ formData.linker }}
            </t-form-item>
          </t-col>
        </t-row>
        <t-row style="width: 100%;">
          <t-col :span="2" class="title"><span class="require">*</span>联系电话</t-col>
          <t-col :span="10">
            <t-form-item name="linkerPhone">
              {{ formData.linkerPhone }}
            </t-form-item>
          </t-col>
        </t-row>
      </t-col>
    </t-row>
    <t-row style="min-height: 300px">
      <t-col :span="2" class="title"><span class="require">*</span>提供验收的技术文件清单</t-col>
      <t-col :span="10" style="justify-content: center">
        <t-table size="small" row-key="id" :columns="projectFileColumns" :data="projectFileData">
          <template #id="{row, rowIndex}">
            {{ rowIndex+1 }}
          </template>
          <template #files="{row}">
            <div v-for="(item,index) in row.fileLists" :key="index">
              <a class="t-button-link" target="_blank" :href="item.url" >
                {{item.name}}
              </a>
            </div>
          </template>
          <template #c1="{row}">
            <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
            <div v-else>{{ row.c1 }}</div>
          </template>
        </t-table>
      </t-col>
    </t-row>
  </t-form>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import {getFiles} from "@/api/common";
import {parseTime} from "@/utils/common";

export default {
  name: "acceptance-detail",
  props:{
    objId: [String,Number],
  },
  data(){
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      file_domain: VITE_FILE_DOMAIN,
      projectFileData: [
        {
          id: 1,
          c1: import.meta.env.VITE_SITE_TAG === 'jtt' ? "《江西省交通运输厅科技示范工程验收申请表》（需要盖章）" : "《江西省交通投资集团有限责任公司科技示范工程验收申请表》（需要盖章）",
          c2: "是",
          moduleKey: "projectYSSQB",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 2,
          c1: "科技示范工程依托工程(项目)已通过验收或总结评价等",
          c2: "是",
          moduleKey: "projectYSZJPJ",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 3,
          c1: "科技示范工程实施方案中明确的实施内容和预期目标已全部完成",
          c2: "是",
          moduleKey: "projectYSSSNJYQMB",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 4,
          c1: "依托科技示范工程实施的省厅科技项目已通过验收",
          c2: "否",
          moduleKey: "projectYSYTGSS",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 5,
          c1: "验收意见",
          c2: "否",
          moduleKey: "projectYSYJ",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 6,
          c1: "相关成果证明",
          c2: "否",
          moduleKey: "projectYSCGZM",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 7,
          c1: "其他",
          c2: "否",
          moduleKey: "projectYSQT",
          fileIds: [],
          fileLists: [],
          require: false,
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "files",
          title: "附件列表",
          align: "left",
        },
      ],
      formData: {
        id: null,
        linker: '',
        linkerPhone: '',
        acceptanceDate: '',
      },
      companyList: [],
      projectData: {
        projectLeader: {
          name: ''
        }
      },
      implementPlanData: {
        startDate: '',
        endDate: '',
        projectCompanyList: []
      }
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getObj();
        }
      }
    },
  },
  methods:{
    parseTime,
    getObj() {
      this.$api.kjsf.project.get(this.objId).then(pro => {
        if(pro.data.createUserId===Number(this.$store.state.user.userId)){
          this.isMyProject = true;
        }
        this.projectData = pro.data;
        this.$api.kjsf.implement.projectEmbodimentGetByProjectId(this.objId).then(response => {
          if (response.data) {
            Object.assign(this.implementPlanData, response.data)
            this.companyList = this.implementPlanData.projectCompanyList.filter(val => val.type === '2').map(val => val.name)
          }
          this.applyLoading = false;
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
        getFiles(this.objId).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val, index) => {
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
        });
        this.$api.kjsf.acceptance.getByProject(this.objId).then(response => {
          if (response.data) {
            Object.assign(this.formData, response.data)
          }
          this.applyLoading = false;
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("reload");
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped>

</style>
